import 'dart:core';

import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

import 'base_style_widget.dart';

class CommonStyleWidget extends BaseStyleWidget {
  DlgStyle style = DlgStyle(
    cancelColor: const Color(0xFF9A989B),
    okColor: const Color(0xFFFFFFFF),
  );

  CommonStyleWidget({
    super.key,
    super.title,
    super.subTitle,
    super.content,
    super.contentWidget,
    super.onCancelTap,
    super.onOkTap,
    super.onCloseTap,
    super.cancelText = '取消',
    super.cancelColor,
    super.okColor,
    super.okText = '确定',
    super.okWidget,
    super.tag,
    super.showCloseBtn,
    super.titleTextAlign,
    super.contentTextAlign,
    super.isTapBtnDismiss,
    super.isSingleBtn = false,
  }) {
    cancelColor ??= style.cancelColor;
    okColor ??= style.okColor;
  }

  @override
  Widget build(BuildContext context) {
    var buttonWeight = Container(
      padding: const EdgeInsets.only(left: 24, right: 24, top: 20, bottom: 18),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            if (!isSingleBtn)
              Expanded(
                child: Row(
                  children: [
                    Expanded(
                      child: GestureDetector(
                        onTap: () {
                          onCancelTap?.call();
                          SmartDialog.dismiss(
                              status: SmartStatus.dialog, tag: tag);
                        },
                        child: Container(
                          decoration: BoxDecoration(
                              color: const Color(0xFFF5F5F5),
                              borderRadius: BorderRadius.circular(8)),
                          height: 40.0,
                          alignment: Alignment.center,
                          child: Text(
                            cancelText,
                            textAlign: TextAlign.center,
                            style:
                                TextStyle(fontSize: 14.0, color: cancelColor),
                          ),
                        ),
                      ),
                    ),
                    const SizedBox(width: 10.0),
                  ],
                ),
              ),
            Expanded(
                child: okWidget ??
                    GestureDetector(
                        onTap: () {
                          onOkTap?.call();
                          if (isTapBtnDismiss) {
                            SmartDialog.dismiss(
                                status: SmartStatus.dialog, tag: tag);
                          }
                        },
                        child: Container(
                            decoration: BoxDecoration(
                                color: const Color(0xFFE34234),
                                borderRadius: BorderRadius.circular(8)),
                            height: 40.0,
                            alignment: Alignment.center,
                            child: Text(okText,
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                    fontSize: 14.0, color: okColor)))))
          ]),
    );
    return Container(
      width: 280.0,
      decoration: BoxDecoration(
        color: const Color(0xffffffff),
        borderRadius: BorderRadius.circular(8.0),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          //副标题
          Container(
              width: 220.0,
              height: (subTitle != null) ? 30 : 20,
              padding: const EdgeInsets.only(left: 10.0, top: 10.0),
              child: Text(subTitle ?? "",
                  style: const TextStyle(
                      fontSize: 12.0, color: Color(0xff666666)))),
          Offstage(
            offstage: (title == null || title!.isEmpty),
            child: SizedBox(
                width: 240.0,
                child: Text(title!,
                    textAlign: titleTextAlign,
                    style: const TextStyle(
                        fontSize: 18,
                        color: Color(0xFF363538),
                        fontWeight: FontWeight.w500))),
          ),
          const SizedBox(height: 18.0),
          Offstage(
              offstage: (content == null || content!.isEmpty) &&
                  contentWidget == null,
              child: SizedBox(
                  width: 240.0,
                  child: content != null
                      ? Text(content ?? "",
                          textAlign: contentTextAlign,
                          style: const TextStyle(
                              fontSize: 14.0, color: const Color(0xff999999)))
                      : contentWidget ?? Container())),
          const SizedBox(height: 20.0),
          // Container(width: 280.0, height: 0.5, color: const Color(0xffEDEDED)),
          buttonWeight
        ],
      ),
    );
  }
}
